module.exports = {
  PutLatitude:function (params, callback) {
    if (!params.EntityName || !params.value || !params.id) return callback();

    var model = global.App.models[params.EntityName];
    model.findOne({where:{"id.keyword":params.value}}, function (err, arr) {
      try {
        if (err) return callback();
        let obj = null;
        let entity = {"es-index":params.index, "es-type": params.type, "es-id": params.id, "systeminfo": params.systeminfo};
        if (arr){
          obj = arr;
          if (!obj["es-Entitys"].find((x) => x["es-id"] == params.id)) obj["es-Entitys"].push(entity);
          else  return callback();
        }else {
          obj = {"id": params.value, "值": params.value, "描述": "自动化过程", "es-Entitys": [entity], createtime: new Date().getTime()};
        }
        model.upsert(obj, function () {
          callback();
        });
      }catch (e){
        callback();
      }
    });
  },
  DeleteAll: function (name, callback) {
    var model = global.App.models[name];
    model.count({},function (err,count) {
      model.destroyAll({},function (err,info) {
        callback(err,{"deletecount":count});
      });
    });
  }
};
